﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using TB.DataModel.DTO;
using TB.BLL;
using System.Threading;
using System.Web.Script.Serialization;
using System.Web.Services;
using System.Web.Script.Services;

namespace TB.Site
{
    public partial class Display : System.Web.UI.Page
    {
        //public MessageHandler MessageHandler { get; set; }

        public string msgsList { get; set; }
        //private IList<Message> msgs;
       
        protected void Page_Load(object sender, EventArgs e)
        {
            msgsList = FillMessages();
        }

        [WebMethod(EnableSession = true)]
        [ScriptMethod(UseHttpGet = false, ResponseFormat = ResponseFormat.Json)]
        public string RefillMessages()
        {
            return FillMessages();
        }

        private string FillMessages()
        {
            var msgs = SessionData.MessageHandler.GetAllMessages();
            msgs = SessionData.MessageHandler.ShufelMessages(msgs);

            return new JavaScriptSerializer().Serialize(msgs);
        }
    }
}